/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import domain.Userdom;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;


/**
 *
 * @author Alejandro
 */
public class UserDao {

    //EntityManagerFactory emf;
    EntityManager em;
    EntityTransaction tx;

    public UserDao() {
        em = SingletonDao.getInstance().getEntityManager();
        tx = SingletonDao.getTx();
    }

    public Userdom getUser(String user) {
        Userdom u = (Userdom) em.createNativeQuery("select * from userdom as u where u.nick='"+user+"'", Userdom.class).getSingleResult();
        return u;
    }

    public void saveUser(Userdom u) {
        tx.begin();
        em.persist(u);
        tx.commit();
    }

    public void updateUser(Userdom u){
        tx.begin();
        em.createNativeQuery("update userdom set pass='"+u.getPass()+"', name='"+u.getName()+"', surname='"+u.getSurname()+"' where nick='"+u.getNick()+"'").executeUpdate();
        tx.commit();
    }

    
}
